package demo3;

public class Main {

    public static void fun(Shape shape){
        shape.getArea();
    }

    public static void main(String[] args) {
        Shape circle = new Circle(2);
        Shape rectangle = new Rectangle(2,2);

        Shape[] shapes =new Shape[]{circle,rectangle};

        for (int i = 0; i < shapes.length; i++) {
            shapes[i].getArea();
        }

        for (Shape shape : shapes){
            shape.getArea();
        }
    }
}

class Shape{
    public void getArea(){

    }
}

class Circle extends Shape{
    double r;

    public Circle(double r) {
        this.r = r;
    }

    @Override
    public void getArea() {
        System.out.println(3.14*r*r);
    }
}

class Rectangle extends Shape{
    double length;
    double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public void getArea() {
        System.out.println(length*width);
    }
}